package zjitc.servlet;

import zjitc.service.UserService;
import zjitc.service.UserServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet("/deleteUserServlet")
public class DeleteUserServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //设置编码
        request.setCharacterEncoding("utf-8");
        //获取数据
        String id = request.getParameter("id");
        //调用service层进行删除
        UserService service = new UserServiceImpl();
        service.deleteUser(id);

        //进行重定向跳转
        response.sendRedirect(request.getContextPath()+"/userListServlet");
    }
}
